import axios from 'axios'
import { fromJS } from 'immutable'
import * as types from './action-types'

const setSearchListAction = (data) => ({
  type: types['SET_SEARCH_LIST'],
  value: fromJS(data)
})

export const getSearchFocusAction = () => ({
  type: types['SEARCH_FOCUS']
})

export const getSearchBlurAction = () => ({
  type: types['SEARCH_BLUR']
})

export const setSearchMouseIn = (bool) => ({
  type: types['SET_SEARCH_MOUSEIN'],
  value: bool
})

export const setSearchPage = (page) => ({
  type: types['SET_SEARCH_PAGE'],
  value: page
})

export const getSearchListAction = () => {
  return (dispatch) => {
    axios.get('/api/headerList.json')
      .then(res => {
        const result = res.data
        if (result.success) {
          dispatch(setSearchListAction(result.data))
        }
      })
  }
}
